package com.ysyc.driver_ee.widget;/**
 * Created by Administrator on 2017/4/12.
 */

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.ysyc.driver_ee.R;
import com.ysyc.driver_ee.tools.ScreenUtils;

import androidx.annotation.ColorRes;
import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * App公用头部布局
 */
public class NoActionBarView extends LinearLayout {

    @BindView(R.id.topView_layout)
    RelativeLayout topViewLayout;
    private View view;


    public NoActionBarView(Context context) {
        super(context);
        initView(context);

    }

    public void setNoBarbackground(@ColorRes int colors) {
        topViewLayout.setBackgroundColor(colors);
    }

    public void setBg( int resource) {
        topViewLayout.setBackgroundResource(resource);
    }


    private void initView(Context context) {
        view = LayoutInflater.from(context).inflate(R.layout.title_no_action_layout, this);
        ButterKnife.bind(view);
        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                int stutasHeight = ScreenUtils.getStatusHeight(getContext());
                topViewLayout.getLayoutParams().height = stutasHeight;
                topViewLayout.setPadding(0, stutasHeight, 0, 0);

            }
        });
    }

    public NoActionBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public NoActionBarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }









}
